<?php

namespace App\Admin\Controllers;

use App\Models\ActivityRecharge;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class ActivityRechargeController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '充值赠送活动';

    protected $status = [ 1 => '正常', 2 => '禁用'];
    protected $statusSwitch = [
            'on' => ['text' => '正常', 'value' => 1, 'color' => 'success'],
            'off' => ['text' => '禁用', 'value' => 2, 'color' => 'danger']
        ];
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new ActivityRecharge());

        $grid->column('name', __('Name'));
        $grid->column('price', __('Price'))->display(function($data){
            return '￥'.$data;
        });
        $grid->column('give', __('Give'))->display(function($data){
            return '￥'.$data;
        });
        $grid->column('status', __('Status'))->switch($this->statusSwitch);
        $grid->column('start_time', __('Start time'))->display(function($data){
        	return $data;
        });
        $grid->column('end_time', __('End time'))->display(function($data){
        	return $data;
        });
        $grid->column('created_at', __('Created at'));
        
        $grid->filter(function ($filter) {
        	$filter->disableIdFilter();
        	$filter->like('name', '名称');
        });

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(ActivityRecharge::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('name', __('Name'));
        $show->field('price', __('Price'));
        $show->field('give', __('Give'));
        $show->field('status', __('Status'));
        $show->field('start_time', __('Start time'));
        $show->field('end_time', __('End time'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));
        $show->field('deleted_at', __('Deleted at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new ActivityRecharge());

        $form->text('name', __('Name'));
        $form->currency('price', __('Price'))->symbol('￥');
        $form->currency('give', __('Give'))->symbol('￥');
        $form->switch('status', __('Status'))->options($this->statusSwitch)->default(1);
        $form->datetime('start_time', __('Start time'));
        $form->datetime('end_time', __('End time'));

        return $form;
    }
}
